package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.SmsHomeBrandMapper;
import com.mail.dubbo.mapper.SmsHomeNewProductMapper;
import com.mail.model.db.SmsHomeBrand;
import com.mail.model.db.SmsHomeNewProduct;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeNewProductApiImpl implements SmsHomeNewProductApi{

    @Autowired
    private SmsHomeNewProductMapper smsHomeNewProductMapper;

    @Override
    public void save(SmsHomeNewProduct newProduct) {
        smsHomeNewProductMapper.insert(newProduct);
    }

    @Override
    public void deleteNewProduc(List<Long> ids) {
        smsHomeNewProductMapper.deleteBatchIds(ids);
    }

    @Override
    public Page<SmsHomeNewProduct> getNewProducByPage(Long pageNum, Long pageSize, String productName, Integer recommendStatus) {
        Page<SmsHomeNewProduct> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsHomeNewProduct> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(productName), SmsHomeNewProduct::getProductName, productName)
                .eq(recommendStatus != null, SmsHomeNewProduct::getRecommendStatus, recommendStatus);
        Page<SmsHomeNewProduct> page1 = smsHomeNewProductMapper.selectPage(page, wrapper);
        return page1;
    }

    @Override
    public void updateNewProduct(Long id, Integer recommendStatus) {
        SmsHomeNewProduct newProduct = new SmsHomeNewProduct();
        newProduct.setId(id);
        newProduct.setRecommendStatus(recommendStatus);
        smsHomeNewProductMapper.updateById(newProduct);
    }

    @Override
    public void updatesortNewProduct(Long id, Integer sort) {
        SmsHomeNewProduct newProduct = new SmsHomeNewProduct();
        newProduct.setId(id);
        newProduct.setSort(sort);
        smsHomeNewProductMapper.updateById(newProduct);
    }
}
